package tech.aistar.controller.authordis;

import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import tech.aistar.entity.authordis.Traveler;
import tech.aistar.entity.authordis.UserTable;
import tech.aistar.service.authordis.INoteAuthorDisService;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by lenovo on 2019/9/28.
 */
@Controller
@RequestMapping("/noteAuthorDis")
public class NoteAuthorDis {

    @Autowired
    private INoteAuthorDisService noteAuthorDisService;

    @GetMapping("/authordis")
    public String authordis() {
        return "authordis/traveler_list";
    }


    //    随机选择达人展示
    @GetMapping("/listAuthor")
    public String listAuthor(Model model) {

        List<UserTable> userTables = new ArrayList<>();

//        随即查询二十个达人进行展示
//        for (int i=0;i<20;i++){
//
//            Traveler traveler=noteAuthorDisService.findAuthorRandom();
//
//            Integer perId= traveler.getPerId();
//
//            UserTable userTable = noteAuthorDisService.findUserInfoByUserId(perId);
//
//            userTables.add(userTable);
//
//        }
        Set<UserTable> set = new HashSet<>();
        while (set.size()<16) {
            List<Traveler> travelers = noteAuthorDisService.findAuthorRandom();
            for (Traveler t : travelers) {
                Integer perId = t.getPerId();
                UserTable userTable = noteAuthorDisService.findUserInfoByUserId(perId);
                set.add(userTable);
                if (set.size()==16){
                    break;
                }
            }

        }
//        System.err.println(userTables);
//        List<Traveler> travelers = noteAuthorDisService.findAuthorRandom();
//        List<UserTable> set = new ArrayList<>();
//            for (Traveler t : travelers) {
//                Integer perId = t.getPerId();
//                UserTable userTable = noteAuthorDisService.findUserInfoByUserId(perId);
//                set.add(userTable);
//            }
        model.addAttribute("userTables", set);

//        return "authordis/traveler_list";

        return "authordis/travelerRandom";


    }

}
